package com.ciwong.epaper.modules.wordlist;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import com.ciwong.mobilelib.utils.ToastUtil;
import com.ciwong.mobilelib.widget.CWPopMenu;

/**
 * BaseFrameLayout
 *
 * @author young
 * @version ciwong v.2.0 2018/4/2 18:34
 * @since ciwong v.2.0
 */

public class BaseWordFrameLayot extends FrameLayout {
    Handler mHandler = new Handler();


    private WordListBottomView wordBottomView;


    private CWPopMenu popMenu;

    private long userId;

    public BaseWordFrameLayot(Context context)
    {
        super(context);
    }

    public BaseWordFrameLayot(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public BaseWordFrameLayot(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public void initData( WordListBottomView wordBottomView, long userId)
    {
        this.wordBottomView=wordBottomView;
        this.userId = userId;
    }

    /**
     * 重置到初始状态
     */
    public void resetInitState()
    {
        resetInitState(true);
    }

    public void resetInitState(final boolean isShow)
    {//初始状态
        if (wordBottomView==null)
        {
            return;
        }

        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {//初始状态
                wordBottomView.setInitState();
            }
        });
    }

    /*
     *播放提示音时图标状态
     */
    public void  playHintState(){
        if (wordBottomView == null)
        {
            return;
        }
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                wordBottomView.playHintState();
            }
        });

    }

    /**
     *  开始录音语句
     *  录音状态
     */
    public void startRecord()
    {
        if (wordBottomView == null)
        {
            return;
        }
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                wordBottomView.recordingState();
            }
        });
    }
    /**
     * 自动更新进度
     */
    public void autoUpdateProgress(final  int timer){
        if (wordBottomView == null)
        {
            return;
        }
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                wordBottomView.autoUpdateProgress(timer);
            }
        });
    }


    /**
     * 开始播放单词状态
     *
     */
    public void play()
    {
        if (wordBottomView == null)
        {
            return;
        }
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                wordBottomView.payWordsState();
            }
        });
    }


    public  void setWordLoading(final boolean loading){
        if (wordBottomView == null)
        {
            return;
        }
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                wordBottomView.setWordLoadState(loading);

            }
        });
    }

    public void showAndgoneNextBtn(final  boolean isShow,final  boolean islast){

        if (wordBottomView == null)
        {
            return;
        }
        mHandler.post(new Runnable()
        {
            @Override
            public void run()
            {
                wordBottomView.showNextBtn(isShow,islast);
            }
        });
    }
}
